using System;
using System.Collections.Generic;
using System.Text;

namespace ClientGUI.Util
{
    /// <summary>
    /// Some random converters for use.
    /// </summary>
    public class Convertors
    {
        /// <summary> 
        /// Two characters only!
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        public static int HexToInt(String hex)
        {
            int num = 0;
            for (int i = 0; i < hex.Length; ++i)
            {
                if (hex[i] >= '0' && hex[i] <= '9')
                {
                    num += (hex[i] - '0') * ((int)Math.Pow(16, i));
                }
                else if (hex[i] >= 'A' && hex[i] <= 'F')
                {
                    num += (hex[i] - 'A' + 10) * ((int)Math.Pow(16, i));
                }
                else
                    throw new Exception("Bad hex value!");
            }
            return num;
        }
    }
}
